package com.topfinance.cnaps2.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;

import com.topfinance.cnaps2.dto.ConfInPortDto;
import com.topfinance.cnaps2.ebo.ConfInPortEbo;
import com.topfinance.cnaps2.ebo.ConfOutPortEbo;
import com.topfinance.cnaps2.ebo.ConfProtocolEbo;
import com.topfinance.cnaps2.ebo.ConfTransportEbo;
import com.topfinance.cnaps2.service.IInPortManager;
import com.topfinance.frame.dao.HibernateEntityDao;
import com.topfinance.frame.exception.AppException;
import com.topfinance.payment.ebo.TCfgNodeEbo;
import com.topfinance.payment.ebo.TCfgProtocolEbo;

/**
 * 该类自动实现了dao的一般方法，如add, remove, update
 * 在service中出现的大部分情况下是在向后台提交数据前的处理(如校验)及获取后台数据后的处理等
 * @author
 *
 */

public class InPortManagerImpl extends HibernateEntityDao<ConfInPortEbo> implements IInPortManager {

	private static final Log log = LogFactory.getLog(InPortManagerImpl.class);

	public void addInPort(ConfInPortDto pt) throws AppException{
		ConfTransportEbo to = (ConfTransportEbo)get(ConfTransportEbo.class,pt.getTID());
		TCfgProtocolEbo po = (TCfgProtocolEbo)get(TCfgProtocolEbo.class,pt.getPID());
		TCfgNodeEbo no = (TCfgNodeEbo)get(TCfgNodeEbo.class,pt.getNID());
		ConfOutPortEbo opo = (ConfOutPortEbo)get(ConfOutPortEbo.class,pt.getAckpID());
		ConfInPortEbo p = new ConfInPortEbo();
		BeanUtils.copyProperties(pt, p);
		p.setNodeEbo(no);
		p.setTransEbo(to);
		p.setPrtclEbo(po);
		p.setAckEbo(opo);
		save(p);
    }
	
	public void editInPort(ConfInPortDto pt) throws AppException{
		ConfTransportEbo to = (ConfTransportEbo)get(ConfTransportEbo.class,pt.getTID());
		TCfgProtocolEbo po = (TCfgProtocolEbo)get(TCfgProtocolEbo.class,pt.getPID());
		TCfgNodeEbo no = (TCfgNodeEbo)get(TCfgNodeEbo.class,pt.getNID());
		ConfOutPortEbo opo = (ConfOutPortEbo)get(ConfOutPortEbo.class,pt.getAckpID());
		ConfInPortEbo p = new ConfInPortEbo();
		BeanUtils.copyProperties(pt, p);
		p.setNodeEbo(no);
		p.setTransEbo(to);
		p.setPrtclEbo(po);
		p.setAckEbo(opo);
		update(p);
    }
	
	//获得传输协议	
	public ConfInPortEbo getInPort(Integer uid) throws AppException{
		return (ConfInPortEbo)get(uid);
	}

	public void deleteInPort(ConfInPortDto o) throws AppException{
		removeById(ConfInPortEbo.class,o.getUid());
    }
	public void deleteInPort(Integer id) throws AppException{
		removeById(ConfInPortEbo.class,id);
	}

	//获得传输协议列表
	public List getAllInPortList() throws AppException{
		String hql = " from ConfInPortEbo t " ;
		String where = "";
		List<Object> paramList = new ArrayList<Object>();
		if (isNotBlank(where)) {
			where = " where " + where;
		}
		hql = hql + where;
		return find(hql,paramList.toArray());		
	}
}
